package com.sky.controller.admin;

import com.sky.dto.VipDTO;
import com.sky.dto.VipPageQueryDTO;
import com.sky.entity.Vip;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.VipService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/vip")
@Slf4j
@Api(tags = "会员相关接口")
public class VipController {

    @Autowired
    private VipService vipService;

    /**
     * 新增会员
     * @param vipDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增会员")
    public Result save(@RequestBody VipDTO vipDTO) {
        log.info("新增会员：{}", vipDTO);
        vipService.save(vipDTO);
        return Result.success();
    }

    /**
     * 删除会员
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除会员")
    public Result delete(@PathVariable Long id) {
        log.info("删除会员：{}", id);
        vipService.delete(id);
        return Result.success();
    }

    /**
     * 编辑会员信息
     * @param vipDTO
     * @return
     */
    @PutMapping
    @ApiOperation("编辑会员信息")
    public Result update(@RequestBody VipDTO vipDTO) {
        log.info("编辑会员信息：{}", vipDTO);
        vipService.update(vipDTO);
        return Result.success();
    }

    /**
     * 会员分页查询
     * @param vipPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("会员分页查询")
    public Result<PageResult> page(VipPageQueryDTO vipPageQueryDTO) {
        log.info("会员分页查询，参数为：{}", vipPageQueryDTO);
        PageResult pageResult = vipService.pageQuery(vipPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据id查询会员信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询会员信息")
    public Result<Vip> getById(@PathVariable Long id) {
        Vip vip = vipService.getById(id);
        return Result.success(vip);
    }

    /**
     * 根据userid查询会员信息
     * @param userId
     * @return
     */
    @GetMapping("/user/{userId}")
    @ApiOperation("根据user_id查询会员信息")
    public Result<Vip> getByUserId(@PathVariable Long userId) {
        Vip vip = vipService.getByUserId(userId);
        return Result.success(vip);
    }
} 